package com.itheima.web.controller.pms;


import com.itheima.service.pms.ISkuStockService;
import com.itheima.utils.ResultData;
import com.itheima.vo.pms.SkuStock;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * sku的库存 前端控制器
 */
@RestController
@RequestMapping("/sku")
@Slf4j
public class SkuStockController {
    @DubboReference
    private ISkuStockService skuStockService;

    @PostMapping("/update/{pid}")
    public ResultData update(@PathVariable("pid") Long pid, @RequestBody List<SkuStock> list)
    {
        list.stream().map(item->{
            item.setProductId(pid);
            return item;
        }).collect(Collectors.toList());
        skuStockService.updateBatchById(list);
        return new ResultData(200,"","");
    }

    @GetMapping("{pid}")
   public ResultData getById(@PathVariable("pid") Long pid,@RequestParam String keyword){
        log.info("pid:{}",pid);
        List<SkuStock> list=skuStockService.getlist(pid,keyword);
        return ResultData.ok("查询成功",list);
    }

}

